package com.htt.app.bienbaogiaothong;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.analytics.tracking.android.EasyTracker;
import com.htt.app.bienbaogiaothong.menu.Menu;
import com.htt.app.bienbaogiaothong.task.LoadImageAssets;
import com.htt.app.bienbaogiaothong.utils.Utils;

public class DetailsActivity extends Activity implements OnClickListener{
	private ImageButton btnMenu;
	private ImageButton btnShare;
	
	private TextView tvTitle;
	private ImageView img;
	private TextView tvNumber;
	private TextView tvName;
	private TextView tvDetail;

	private String name;
	private String detail;
	private String image;
	private String number;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.details);
		initLayout();
		
		image = getIntent().getStringExtra("image");
		name = getIntent().getStringExtra("name");
		detail = getIntent().getStringExtra("detail");
		number = getIntent().getStringExtra("number");
		
		if(Utils.haveNetworkConnection(this)) {
			tvTitle.setText(name);
			tvNumber.setText(number);
			tvName.setText(name);
			tvDetail.setText(detail);
			
			LoadImageAssets loadImage = new LoadImageAssets(getAssets(), img, image);
			loadImage.execute();
			
		} else
			Utils.showDialog(this,
							getResources().getString(R.string.error_connect),
							getResources().getString(R.string.connect_info));
		
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		EasyTracker.getInstance().activityStart(this);
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		EasyTracker.getInstance().activityStop(this);
	}
	
	private void initLayout() {
		btnMenu = (ImageButton) findViewById(R.id.details_btnMenu);
		btnShare = (ImageButton) findViewById(R.id.details_btnShare);
		
		tvTitle = (TextView) findViewById(R.id.details_title);
		img = (ImageView) findViewById(R.id.detail_img);
		tvNumber = (TextView) findViewById(R.id.detail_number);
		tvName = (TextView) findViewById(R.id.detail_name);
		tvDetail = (TextView) findViewById(R.id.detail_details);
		
		btnMenu.setOnClickListener(this);
		btnShare.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v == btnMenu) {
			Menu.rateApp(this);
		} else if(v == btnShare) {
			Menu.share(this);
		}
	}
	
}
